package com.zhc.dejingapi.utils.qing;

//import com.alibaba.fastjson.JSON;

import com.google.gson.Gson;
import com.zhc.dejingapi.entity.BomworkEntity;
import com.zhc.dejingapi.entity.QingAppfieldsEntity;
import com.zhc.dejingapi.entity.QingFcmoroutingmainEntity;
import com.zhc.dejingapi.entity.QingWaterboiltaskfinishEntity;
import com.zhc.dejingapi.mapper.QingAppfieldsMapper;
import com.zhc.dejingapi.mapper.QingAppfieldtablevaluesMapper;
import com.zhc.dejingapi.pojo.erp.BomworkMainUpdModel;
import com.zhc.dejingapi.pojo.erp.BomworkRoutingUpdModel;
import com.zhc.dejingapi.pojo.param.QingFcmoroutingDetailParam;
import com.zhc.dejingapi.pojo.param.QingFcmoroutingMainParam;
import com.zhc.dejingapi.pojo.param.QingWaterboiltaskfinishParam;
import com.zhc.dejingapi.pojo.qingflow.QingflowApiInfo;
import com.zhc.dejingapi.pojo.qingflow.appdata.adddata.*;
import com.zhc.dejingapi.pojo.qingflow.appdata.deldata.QingDelDataModel;
import com.zhc.dejingapi.pojo.qingflow.appdata.editdata.QingEditDataFieldModel;
import com.zhc.dejingapi.pojo.qingflow.appdata.editdata.QingEditDataFieldValueModel;
import com.zhc.dejingapi.pojo.qingflow.appdata.editdata.QingEditWithTblDataFieldModel;
import com.zhc.dejingapi.pojo.qingflow.appdata.editdata.QingEditWithTblDataModel;
import com.zhc.dejingapi.pojo.qingflow.appfield.QingFieldDataItemTableRowValueWithDetailBase;
import com.zhc.dejingapi.pojo.qingflow.appfield.QingFieldDataItemWithDetailBase;
import org.apache.commons.beanutils.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class FCMoRoutingUploadUtils {

    private static final Logger log = LoggerFactory.getLogger(FCMoRoutingUploadUtils.class);

    public FCMoRoutingUploadUtils(QingflowApiInfo qqingflowApiInfo1, JdbcTemplate mysqlJdbcTemplate1,
                                  QingAppfieldsMapper qingAppfieldsMapper1,
                                  QingAppfieldtablevaluesMapper qingAppfieldTableValuesMapper1,
                                  Map<String,String> mapContrastFields1,
                                  Map<String,String> mapContrastDetailFields1,
                                  String  strErpTableName)throws Exception{

        this.qqingflowApiInfo=qqingflowApiInfo1;
        this.mysqlJdbcTemplate=mysqlJdbcTemplate1;
        this.qingAppfieldsMapper=qingAppfieldsMapper1;
        this.qingAppfieldtablevaluesMapper = qingAppfieldTableValuesMapper1;
        this.mapContrastMainFields=mapContrastFields1;
        this.mapContrastDetailFields=mapContrastDetailFields1;
        if (!(strErpTableName==null||strErpTableName.isEmpty())){
            this.erpTableName=strErpTableName;
        }
        //LoadContrastFields();
        LoadInfo();
    }


    private Map<String,String> mapContrastMainFields=null;

    private Map<String,String> mapContrastDetailFields=null;

    private String erpTableName="bomwork";
    private Long appMainId;
    private String appKey;
    private JdbcTemplate mysqlJdbcTemplate;
    private QingflowApiInfo qqingflowApiInfo;

    private QingAppfieldsMapper qingAppfieldsMapper;

    private QingAppfieldtablevaluesMapper qingAppfieldtablevaluesMapper;


    private List<QingFieldDataItemWithDetailBase> listFields=null;

    private void LoadInfo() throws Exception{


        String strSql="SELECT appMainId\n" +
                "from  appinferpinfocontrast\n" +
                "where erpTableName=?";
        appMainId=mysqlJdbcTemplate.queryForObject(strSql,Long.class,erpTableName);
        if (appMainId==null){
            throw new Exception("ERP表名"+erpTableName+"没有找到对应的appMainId");
        }
        strSql="SELECT appKey\n" +
                "from qing_appinfo\n" +
                "where main_id=?";
        appKey=mysqlJdbcTemplate.queryForObject(strSql,String.class,appMainId);
        if (appKey==null||appKey.isEmpty()){
            throw new Exception("ERP表名"+erpTableName+"没有找到对应的appKey");
        }

        //QueryWrapper<QingAppfieldsEntity> queryWrapper=new QueryWrapper<>();
        //queryWrapper.eq("appMain_Id",appMainId)
        //        .gt("queId",1000000);

        strSql="SELECT * from qing_appfields where appMain_Id=? and queId>1000000";

        //List<User> userList = jdbcTemplate.query(sql,/*处理一条一条的数据*/new UserRowMapper(), "沙僧");

        // listFlows = oaJdbcTemplate.query(strSql, new BeanPropertyRowMapper<>(UserAuditWorkflowModel.class));

        listFields=mysqlJdbcTemplate.query(strSql,new BeanPropertyRowMapper<>(QingFieldDataItemWithDetailBase.class),appMainId);


        //listFields=qingAppfieldsMapper.selectList(queryWrapper);
        if (listFields==null||listFields.isEmpty()){
            throw new Exception("ERP表名"+erpTableName+"没有找到对应的字段信息");
        }
        for (int i = 0; i <listFields.size() ; i++) {
            try{
                listFields.get(i).LoadDetailRowField(mysqlJdbcTemplate);

            }
            catch (Exception e){
                e.printStackTrace();
                log.error("ERP表名"+erpTableName+"字段信息"+listFields.get(i).getQueTitle()+"没有找到对应的字段信息");
            }

        }

    }

    public QingAddDataResultMain AddEntity(QingFcmoroutingMainParam entity){
        QingAddDataResultMain resultMain=null;

        try{

            QingAddDataWithTblRowMainModel qingAddDataModel =new QingAddDataWithTblRowMainModel();

            QingAddDataUserModel dataUserModel=new QingAddDataUserModel();
            dataUserModel.setMobile(qqingflowApiInfo.getUserMobile());
            dataUserModel.setEmail(qqingflowApiInfo.getUserEmail());
            dataUserModel.setAreaCode(qqingflowApiInfo.getUserAreacode());
            qingAddDataModel.setApplyUser(dataUserModel);


            List<QingAddDataWithTableRowModel> listFieldModels=new ArrayList<>();

            for (int i = 0; i < listFields.size(); i++) {
                QingFieldDataItemWithDetailBase sourceEntity=listFields.get(i);
                QingAddDataWithTableRowModel addDataFieldModel=new QingAddDataWithTableRowModel();
                //QingAddDataFieldValueModel addDataFieldValueModel=new QingAddDataFieldValueModel();

                if (sourceEntity.getQueTitle().equals("状态")){
                    // 获取属性值，属性名为"myField"
                    //Object objValue = PropertyUtils.getProperty(entity, mapContrastMainFields.get("updAction"));


                        addDataFieldModel=CopyAddData(sourceEntity,"可用");

                    listFieldModels.add(addDataFieldModel);

                }else {

                    String strTitle=sourceEntity.getQueTitle();

                    if(mapContrastMainFields.containsKey(strTitle)){
                        try{
                            // 获取属性值，属性名为"myField"
                            Object objValue = PropertyUtils.getProperty(entity, mapContrastMainFields.get(strTitle));

                            if(objValue==null){
                                //addDataFieldModel=CopyAddData(sourceEntity,"");
                                addDataFieldModel=CopyAddData(sourceEntity,null);
                            }
                            else{
                                addDataFieldModel=CopyAddData(sourceEntity,objValue.toString());
                            }

                            //region 子件需要上传
                            if(sourceEntity.getTableRowFields()==null||sourceEntity.getTableRowFields().size()<1){

                            }
                            else {
                                addDataFieldModel=CopyAddData(sourceEntity,null);
                                //有子件需要上传
                                List<List<QingAddDataTableRowValueBase>> tableValues =new ArrayList<>();

                                try{
                                    for ( QingFcmoroutingDetailParam bomworkRoutingModel :entity.getQingFcmoroutingdetail()){

                                        List<QingAddDataTableRowValueBase> listQingAddTableRowValues=new ArrayList<>();

                                        for (QingFieldDataItemTableRowValueWithDetailBase tableRowValueWithDetailBase:sourceEntity.getTableRowFields()){

                                            String strTableRowTitle=tableRowValueWithDetailBase.getQueTitle();

                                            try{
                                                // 获取属性值，属性名为"myField"
                                                Object objValueDetail = PropertyUtils.getProperty(bomworkRoutingModel, mapContrastDetailFields.get(strTableRowTitle));

                                                if(objValueDetail==null){
                                                    //addDataFieldModel=CopyAddData(sourceEntity,"");
                                                    QingAddDataTableRowValueBase tableRowFieldValue=CopyAddTableRowData(tableRowValueWithDetailBase,null);
                                                    listQingAddTableRowValues.add(tableRowFieldValue);
                                                }
                                                else{

                                                    QingAddDataTableRowValueBase tableRowFieldValue=CopyAddTableRowData(tableRowValueWithDetailBase,objValueDetail.toString());
                                                    if (strTableRowTitle.equals("是否为首道工序")||strTableRowTitle.equals("是否为末道工序")){

                                                        if(objValueDetail.toString().equals("是")){
                                                            tableRowFieldValue.getValues().get(0).setId(73834264L);
                                                        }
                                                        else if(objValueDetail.toString().equals("否")){
                                                            tableRowFieldValue.getValues().get(0).setId(73833564L);
                                                        }

                                                    }


                                                    listQingAddTableRowValues.add(tableRowFieldValue);
                                                }

                                                //listFieldModels.add(addDataFieldModel);
                                            }
                                            catch (Exception e){
                                                e.printStackTrace();
                                                log.error("ERP表名"+erpTableName+"字段信息"+tableRowValueWithDetailBase.getQueTitle()+"没有找到对应的字段信息");
                                            }

                                        }

                                        tableValues.add(listQingAddTableRowValues);
                                    }
                                }
                                catch (Exception e ){
                                    e.printStackTrace();

                                }


                                if(tableValues==null||tableValues.size()<1){

                                }
                                else {
                                    //有子件需要上传
                                    addDataFieldModel.setTableValues(tableValues);
                                }

                                //addDataFieldModel.setTableValues(tableValues);

                            }
                            //endregion

                            listFieldModels.add(addDataFieldModel);
                        }
                        catch (Exception e){
                            e.printStackTrace();
                        }

                    }

                }

                //listFieldModels.add(addDataFieldModel);

            }
            if (listFieldModels==null||listFieldModels.size()<1){

            }
            else {
                qingAddDataModel.setAnswers(listFieldModels);
            }

            //转字符串
            //String strJson= JSON.toJSONString(qingAddDataModel);
            Gson gson = new Gson();
            String strJson=gson.toJson(qingAddDataModel);
            //获取返回结果
            resultMain= QingflowAPIUtils.AddDataToQing(qqingflowApiInfo,appKey,strJson);

        }
        catch (Exception e){
            e.printStackTrace();
            log.error("ERP表名"+erpTableName+"上传失败");
            //throw  e;
        }
        return resultMain;
    }

    public QingAddDataResultMain AddWorterBoiledEndEntity(QingWaterboiltaskfinishParam entity){
        QingAddDataResultMain resultMain=null;

        try{

            QingAddDataWithTblRowMainModel qingAddDataModel =new QingAddDataWithTblRowMainModel();

            QingAddDataUserModel dataUserModel=new QingAddDataUserModel();
            dataUserModel.setMobile(qqingflowApiInfo.getUserMobile());
            dataUserModel.setEmail(qqingflowApiInfo.getUserEmail());
            dataUserModel.setAreaCode(qqingflowApiInfo.getUserAreacode());
            qingAddDataModel.setApplyUser(dataUserModel);


            List<QingAddDataWithTableRowModel> listFieldModels=new ArrayList<>();
            for (int i = 0; i < listFields.size(); i++) {
                QingFieldDataItemWithDetailBase sourceEntity=listFields.get(i);
                QingAddDataWithTableRowModel addDataFieldModel=new QingAddDataWithTableRowModel();
                //QingAddDataFieldValueModel addDataFieldValueModel=new QingAddDataFieldValueModel();

                if (sourceEntity.getQueTitle().equals("状态")){
                    // 获取属性值，属性名为"myField"
                    //Object objValue = PropertyUtils.getProperty(entity, mapContrastMainFields.get("updAction"));


                    addDataFieldModel=CopyAddData(sourceEntity,"可用");

                    listFieldModels.add(addDataFieldModel);

                }else {

                    String strTitle=sourceEntity.getQueTitle();

                    if(mapContrastMainFields.containsKey(strTitle)){
                        try{
                            // 获取属性值，属性名为"myField"
                            Object objValue = PropertyUtils.getProperty(entity, mapContrastMainFields.get(strTitle));

                            if(objValue==null){
                                //addDataFieldModel=CopyAddData(sourceEntity,"");
                                addDataFieldModel=CopyAddData(sourceEntity,null);
                            }
                            else{
                                addDataFieldModel=CopyAddData(sourceEntity,objValue.toString());
                            }

                            listFieldModels.add(addDataFieldModel);
                        }
                        catch (Exception e){
                            e.printStackTrace();
                        }

                    }

                }

                //listFieldModels.add(addDataFieldModel);

            }
            if (listFieldModels==null||listFieldModels.size()<1){

            }
            else {
                qingAddDataModel.setAnswers(listFieldModels);
            }

            //转字符串
            //String strJson= JSON.toJSONString(qingAddDataModel);
            Gson gson = new Gson();
            String strJson=gson.toJson(qingAddDataModel);
            //获取返回结果
            resultMain= QingflowAPIUtils.AddDataToQing(qqingflowApiInfo,appKey,strJson);

        }
        catch (Exception e){
            e.printStackTrace();
            log.error("ERP表名"+erpTableName+"上传失败");
            //throw  e;
        }
        return resultMain;
    }

    public QingAddDataResultMain UpdEntity(BomworkMainUpdModel entity, String strActionResult){
        QingAddDataResultMain resultMain=null;
        try{
            //String strAccessToken=accessTokenUtils.getAccessToken(qqingflowApiInfo);

            QingEditWithTblDataModel qingEditDataModel =new QingEditWithTblDataModel();

            List<QingEditWithTblDataFieldModel> listFieldModels=new ArrayList<>();

            for (int i = 0; i < listFields.size(); i++) {
                QingFieldDataItemWithDetailBase sourceEntity=listFields.get(i);
                QingEditWithTblDataFieldModel editDataFieldModel=new QingEditWithTblDataFieldModel();

                if (sourceEntity.getQueTitle().equals("状态")){
                    QingEditDataFieldValueModel addDataFieldValueModel=new QingEditDataFieldValueModel();
                    // 获取属性值，属性名为"myField"
                    //Object objValue = PropertyUtils.getProperty(entity, mapContrastMainFields.get("updAction"));

                    String StrAction=entity.getUpdAction();// "M";
                    //if(objValue==null||objValue.toString().isEmpty()){

                    //}
                    //else{
                    //    StrAction=objValue.toString();
                    //}
                    if (StrAction.toUpperCase().equals("D")){
                        //addDataFieldModel=CopyAddData(sourceEntity,"已删除");
                        addDataFieldValueModel.setValue("已删除");
                    }
                    else{
                        //addDataFieldModel=CopyAddData(sourceEntity,"可用");
                        addDataFieldValueModel.setValue("可用");
                    }

                    List<QingEditDataFieldValueModel> listValues=new ArrayList<>();

                    listValues.add(addDataFieldValueModel);

                    editDataFieldModel.setQueId(sourceEntity.getQueId());

                    editDataFieldModel.setValues(listValues);
                    listFieldModels.add(editDataFieldModel);
                }
                else{
                    String strTitle=sourceEntity.getQueTitle();
                    if(mapContrastMainFields.containsKey(strTitle)){
                        try {
                            // 获取属性值，属性名为"myField"
                            String strFieldName=mapContrastMainFields.get(strTitle);

                            Object objValue = PropertyUtils.getProperty(entity, strFieldName);
                            QingEditDataFieldValueModel addDataFieldValueModel = new QingEditDataFieldValueModel();

                            if(objValue==null){
                                addDataFieldValueModel.setValue(null);
                                log.error(strTitle+"|"+strFieldName);
                            }
                            else {
                                addDataFieldValueModel.setValue(objValue.toString());

                            }
                            List<QingEditDataFieldValueModel> listValues = new ArrayList<>();
                            listValues.add(addDataFieldValueModel);
                            editDataFieldModel.setQueId(sourceEntity.getQueId());
                            editDataFieldModel.setValues(listValues);
                            //region 子件需要上传

                            if(sourceEntity.getTableRowFields()==null||sourceEntity.getTableRowFields().size()<1){

                            }
                            else {
                                //有子件需要上传
                                List<List<QingEditDataFieldModel>> tableValues =new ArrayList<>();

                                for ( BomworkRoutingUpdModel bomworkRoutingUpdModel :entity.getRoutingLists()){

                                    List<QingEditDataFieldModel> listQingAddTableRowValues=new ArrayList<>();

                                    for (QingFieldDataItemTableRowValueWithDetailBase tableRowValueWithDetailBase:sourceEntity.getTableRowFields()){

                                        String strTableRowTitle=tableRowValueWithDetailBase.getQueTitle();

                                        if (mapContrastDetailFields.containsKey(strTableRowTitle)){
                                            try{
                                                // 获取属性值，属性名为"myField"
                                                String strDetailFieldName=mapContrastDetailFields.get(strTableRowTitle);

                                                Object objValueDetail = PropertyUtils.getProperty(bomworkRoutingUpdModel, strDetailFieldName);

                                                if(objValueDetail==null){
                                                    //addDataFieldModel=CopyAddData(sourceEntity,"");
                                                    //QingAddDataTableRowValueBase tableRowFieldValue=CopyAddTableRowData(tableRowValueWithDetailBase,null);

                                                    log.error(strTableRowTitle+"|"+strDetailFieldName+"=null");
                                                    QingEditDataFieldModel tableRowFieldValue=CopyEditTableRowData(tableRowValueWithDetailBase,null);
                                                    listQingAddTableRowValues.add(tableRowFieldValue);
                                                }
                                                else{

                                                    //QingAddDataTableRowValueBase tableRowFieldValue=CopyAddTableRowData(tableRowValueWithDetailBase,objValueDetail.toString());
                                                    QingEditDataFieldModel tableRowFieldValue=CopyEditTableRowData(tableRowValueWithDetailBase,objValueDetail.toString());
                                                    listQingAddTableRowValues.add(tableRowFieldValue);
                                                }

                                                //listFieldModels.add(addDataFieldModel);
                                            }
                                            catch (Exception e){
                                                e.printStackTrace();
                                                log.error("ERP表名"+erpTableName+"字段信息"+tableRowValueWithDetailBase.getQueTitle()+"没有找到对应的字段信息");
                                            }
                                        }

                                    }

                                    tableValues.add(listQingAddTableRowValues);
                                }

                                if(tableValues==null||tableValues.size()<1){

                                }
                                else {
                                    //有子件需要上传
                                    editDataFieldModel.setTableValues(tableValues);
                                }

                                //addDataFieldModel.setTableValues(tableValues);

                            }
                            //endregion

                        }
                        catch (Exception e){
                            e.printStackTrace();
                        }
                        listFieldModels.add(editDataFieldModel);
                    }

                }

            }
            qingEditDataModel.setAnswers(listFieldModels);

            //转字符串
            //String strJson= JSON.toJSONString(qingEditDataModel);
            Gson gson = new Gson();
            String strJson=gson.toJson(qingEditDataModel);
            // 获取属性值，属性名为"myField"
            //Object objValue = PropertyUtils.getProperty(entity, mapContrastMainFields.get("applyId"));

            String strApplyId=entity.getApplyId()+"";// "";
            //if(objValue==null||objValue.toString().isEmpty()){

            //}
            //else{
            //    strApplyId=objValue.toString();
            //}

            //获取返回结果
            resultMain= QingflowAPIUtils.UpdDataToQing(qqingflowApiInfo,appKey,strJson,strApplyId);

        }
        catch (Exception e){
            e.printStackTrace();
            //throw  e;
        }
        return resultMain;
    }

    public QingAddDataResultMain DelEntity(BomworkEntity entity){
        QingAddDataResultMain resultMain=null   ;
        try{
            //String strAccessToken=accessTokenUtils.getAccessToken(qqingflowApiInfo);

            QingDelDataModel qingAddDataModel =new QingDelDataModel();

            List<Long> listDel=new ArrayList<>();

            //applyId
            // 获取属性值，属性名为"myField"
            //Object objValue = PropertyUtils.getProperty(entity, mapContrastMainFields.get("applyId"));

            //String strApplyId="";
            long strApplyIdLong=entity.getApplyId();
//            if(objValue==null||objValue.toString().isEmpty()){
//
//            }
//            else{
//                strApplyId=objValue.toString();
//                try {
//                    strApplyIdLong= Long.parseLong(strApplyId);
//                }
//                catch (Exception e){
//
//                }
//
//            }

            listDel.add(strApplyIdLong);

            qingAddDataModel.setApplyIds(listDel);
            //转字符串
            //String strJson= JSON.toJSONString(qingAddDataModel);
            Gson gson = new Gson();
            String strJson=gson.toJson(qingAddDataModel);
            //获取返回结果
            //qingflowApiInfo qingflowApiInfo, String appKey,String strBody
            resultMain= QingflowAPIUtils.DelDataToQing(qqingflowApiInfo,appKey,strJson);

//            if (resultMain==null){
//
//                entity.setErrCode("-10015");
//                entity.setErrMsg("服务器返回内容为空！");
//                entity.setLastRequestId(null);
//                entity.setIsDeal(0);
//                entity.setIsWaiting(0);
//                entity.setDealDate(LocalDateTime.now());
//                productUnitMapper.updateById(entity);
//
//            }
//            else{
//                if (resultMain.getErrCode()==0){
//                    entity.setErrCode(resultMain.getErrCode().toString());
//                    entity.setErrMsg("提交成功！");
//                    entity.setLastRequestId(resultMain.getResult().getRequestId());
//                    entity.setIsDeal(0);
//                    entity.setIsWaiting(1);
//                    entity.setDealDate(LocalDateTime.now());
//                    entity.setActionResult("D");
//                    productUnitMapper.updateById(entity);
//                    //增加马上判断的结果
//
//                }
//                else{
//                    entity.setErrCode(resultMain.getErrCode().toString());
//                    entity.setErrMsg(resultMain.getErrMsg());
//                    entity.setLastRequestId(null);
//                    entity.setIsDeal(0);
//                    entity.setIsWaiting(0);
//                    entity.setDealDate(LocalDateTime.now());
//                    productUnitMapper.updateById(entity);
//                }
//
//            }

        }
        catch (Exception e){
            e.printStackTrace();
            //throw  e;
        }
        return resultMain;
    }


    public QingAddDataFieldModel CopyAddData(QingAppfieldsEntity fieldEntity,String fieldSetValue){
        QingAddDataFieldModel addDataFieldModel=new QingAddDataFieldModel();

        QingAddDataFieldValueModel addDataFieldValueModel=new QingAddDataFieldValueModel();
        //"dataValue": "可用",
        addDataFieldValueModel.setDataValue(fieldSetValue);
        //"email": null,
        addDataFieldValueModel.setEmail(fieldEntity.getValueEmail());
        //"id": null,
        addDataFieldValueModel.setId(fieldEntity.getValueId());
        //"optionId": null,
        addDataFieldValueModel.setOptionId(fieldEntity.getValueOptionid());
        //"ordinal": null,
        addDataFieldValueModel.setOrdinal(fieldEntity.getValueOrdinal());
        //"otherInfo": null,
        addDataFieldValueModel.setOtherInfo(fieldEntity.getValueOtherinfo());
        //"pluginValue": null,
        addDataFieldValueModel.setPluginValue(fieldEntity.getValuePluginvalue());
        //"queId": 208482472,
        addDataFieldValueModel.setQueId(fieldEntity.getValueQueid());
        //"value": "可用"
        addDataFieldValueModel.setValue(fieldSetValue);


        List<QingAddDataFieldValueModel> list=new ArrayList<>();
        list.add(addDataFieldValueModel);

        //"queId": 208482493,
        addDataFieldModel.setQueId(fieldEntity.getQueId());
        //"queTitle": "分类编号",
        addDataFieldModel.setQueTitle(fieldEntity.getQueTitle());
        //"queType": "2",
        addDataFieldModel.setQueType(fieldEntity.getQueType());
        //"values":
        addDataFieldModel.setValues(list);

        return addDataFieldModel;
    }

    public QingAddDataWithTableRowModel CopyAddData(QingFieldDataItemWithDetailBase fieldEntity,String fieldSetValue){
        QingAddDataWithTableRowModel addDataFieldModel=new QingAddDataWithTableRowModel();

        QingAddDataFieldValueModel addDataFieldValueModel=new QingAddDataFieldValueModel();
        //"dataValue": "可用",
        addDataFieldValueModel.setDataValue(fieldSetValue);
        //"email": null,
        addDataFieldValueModel.setEmail(fieldEntity.getValueEmail());
        //"id": null,
        addDataFieldValueModel.setId(fieldEntity.getValueId());
        //"optionId": null,
        addDataFieldValueModel.setOptionId(fieldEntity.getValueOptionid());
        //"ordinal": null,
        addDataFieldValueModel.setOrdinal(fieldEntity.getValueOrdinal());
        //"otherInfo": null,
        addDataFieldValueModel.setOtherInfo(fieldEntity.getValueOtherinfo());
        //"pluginValue": null,
        addDataFieldValueModel.setPluginValue(fieldEntity.getValuePluginvalue());
        //"queId": 208482472,
        addDataFieldValueModel.setQueId(fieldEntity.getValueQueid());
        //"value": "可用"
        addDataFieldValueModel.setValue(fieldSetValue);


        List<QingAddDataFieldValueModel> list=new ArrayList<>();
        list.add(addDataFieldValueModel);

        //"queId": 208482493,
        addDataFieldModel.setQueId(fieldEntity.getQueId());
        //"queTitle": "分类编号",
        addDataFieldModel.setQueTitle(fieldEntity.getQueTitle());
        //"queType": "2",
        addDataFieldModel.setQueType(fieldEntity.getQueType());
        //"values":
        addDataFieldModel.setValues(list);

        //明细

        if (fieldEntity.getTableRowFields()!=null){

        }

        return addDataFieldModel;
    }


    public QingAddDataTableRowValueBase CopyAddTableRowData(QingFieldDataItemTableRowValueWithDetailBase fieldEntity,String fieldSetValue){
        QingAddDataTableRowValueBase addDataFieldModel=new QingAddDataTableRowValueBase();

        QingAddDataFieldValueModel addDataFieldValueModel=new QingAddDataFieldValueModel();
        //"dataValue": "可用",
        addDataFieldValueModel.setDataValue(fieldSetValue);
        //"email": null,
        addDataFieldValueModel.setEmail(fieldEntity.getValueEmail());
        //"id": null,
        addDataFieldValueModel.setId(fieldEntity.getValueId());
        //"optionId": null,
        addDataFieldValueModel.setOptionId(fieldEntity.getValueOptionid());
        //"ordinal": null,
        addDataFieldValueModel.setOrdinal(fieldEntity.getValueOrdinal());
        //"otherInfo": null,
        addDataFieldValueModel.setOtherInfo(fieldEntity.getValueOtherinfo());
        //"pluginValue": null,
        addDataFieldValueModel.setPluginValue(fieldEntity.getValuePluginvalue());
        //"queId": 208482472,
        addDataFieldValueModel.setQueId(fieldEntity.getValueQueid());
        //"value": "可用"
        addDataFieldValueModel.setValue(fieldSetValue);


        List<QingAddDataFieldValueModel> list=new ArrayList<>();
        list.add(addDataFieldValueModel);

        //"queId": 208482493,
        addDataFieldModel.setQueId(fieldEntity.getQueId());
        //"queTitle": "分类编号",
        addDataFieldModel.setQueTitle(fieldEntity.getQueTitle());
        //"queType": "2",
        addDataFieldModel.setQueType(fieldEntity.getQueType());
        //"values":
        addDataFieldModel.setValues(list);

        //明细


        return addDataFieldModel;
    }

    public QingEditDataFieldModel CopyEditTableRowData(QingFieldDataItemTableRowValueWithDetailBase fieldEntity,String fieldSetValue){
        QingEditDataFieldModel addDataFieldModel=new QingEditDataFieldModel();

        QingEditDataFieldValueModel addDataFieldValueModel=new QingEditDataFieldValueModel();
        //"dataValue": "可用",
        //addDataFieldValueModel.setDataValue(fieldSetValue);
        //"email": null,
        //addDataFieldValueModel.setEmail(fieldEntity.getValueEmail());
        //"id": null,
        //addDataFieldValueModel.setId(fieldEntity.getValueId());
        //"optionId": null,
        //addDataFieldValueModel.setOptionId(fieldEntity.getValueOptionid());
        //"ordinal": null,
        //addDataFieldValueModel.setOrdinal(fieldEntity.getValueOrdinal());
        //"otherInfo": null,
        //addDataFieldValueModel.setOtherInfo(fieldEntity.getValueOtherinfo());
        //"pluginValue": null,
        //addDataFieldValueModel.setPluginValue(fieldEntity.getValuePluginvalue());
        //"queId": 208482472,
        //addDataFieldValueModel.setQueId(fieldEntity.getValueQueid());
        //"value": "可用"
        addDataFieldValueModel.setValue(fieldSetValue);


        List<QingEditDataFieldValueModel> list=new ArrayList<>();
        list.add(addDataFieldValueModel);

        //"queId": 208482493,
        addDataFieldModel.setQueId(fieldEntity.getQueId());
        //"queTitle": "分类编号",
        //addDataFieldModel.setQueTitle(fieldEntity.getQueTitle());
        //"queType": "2",
        //addDataFieldModel.setQueType(fieldEntity.getQueType());
        //"values":
        addDataFieldModel.setValues(list);

        //明细


        return addDataFieldModel;
    }

    public static  QingFcmoroutingmainEntity CopyFromParam(QingFcmoroutingMainParam param){
        QingFcmoroutingmainEntity entity=new QingFcmoroutingmainEntity();

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        String locaDateTimeString="";
        LocalDateTime lLocalDateTime=null    ;

        //    private String appKey;
        entity.setAppKey(param.getAppKey());
        //    private Double calpieSalary;
        entity.setCalpieSalary(param.getCalpieSalary());
        //    private Integer eqId;
        entity.setEqId(param.getEqId());
        //    private LocalDateTime reportJobEndTime;
        locaDateTimeString=param.getReportJobEndTime();

        if(locaDateTimeString==null||locaDateTimeString.isEmpty()){

        }
        else{
            lLocalDateTime= LocalDateTime.parse(locaDateTimeString, formatter);
            entity.setReportJobEndTime(lLocalDateTime);
        }

        //    private String proBatchNo;
        entity.setProBatchNo(param.getProBatchNo());
        //    private String eqCode;
        entity.setEqCode(param.getEqCode());
        //    private LocalDateTime reportJobStartTime;

        locaDateTimeString=param.getReportJobStartTime();
        if(locaDateTimeString==null||locaDateTimeString.isEmpty()){

        }
        else{
            lLocalDateTime= LocalDateTime.parse(locaDateTimeString, formatter);
            entity.setReportJobStartTime(lLocalDateTime);
        }
        //    private String workShiftCode;
        entity.setWorkShiftCode(param.getWorkShiftCode());
        //    private String moldCode;
        entity.setMouldCode(param.getMoldCode());
        //    private Integer leaveQty;
        entity.setLeaveQty(param.getLeaveQty());
        //    private Integer afterQualifyQty;
        entity.setAfterQualifyQty(param.getAfterQualifyQty());
        //    private Integer afterLeaveQty;
        entity.setAfterLeaveQty(param.getAfterLeaveQty());
        //    private String moTaskCode;
        entity.setProcessPlanCode(param.getProcessPlanCode());
        //    private String reportType;
        entity.setReportType(param.getReportType());
        //    private String workTaskCode;
        entity.setZsSendWorkCode(param.getZsSendWorkCode());
        //    private Integer qualifyQty;
        entity.setQualifyQty(param.getQualifyQty());
        //    private String psnCode;//员工工号
        entity.setPsnCode(param.getPsnCode());
        //    private String psnName;
        entity.setPsnName(param.getPsnName());
        //    private String opName;
        entity.setProcessName(param.getProcessName());
        //    private Integer planQty;
        entity.setProdNum(param.getProdNum());
        //    private LocalDateTime reportJobTime;
        locaDateTimeString=param.getReportJobTime();
        if(locaDateTimeString==null||locaDateTimeString.isEmpty()){

        }
        else{
            lLocalDateTime= LocalDateTime.parse(locaDateTimeString, formatter);
            entity.setReportJobTime(lLocalDateTime);
        }
        //    private String invCode;
        entity.setInvCode(param.getInvCode());
        //    private String invStd;
        entity.setInvType(param.getInvType());
        //    private String invName;
        entity.setInvName(param.getInvName());
        //    private Integer scrapQty;
        entity.setScrapQty(param.getScrapQty());
        //    private Integer finishedQty;
        entity.setTotalWorkNum(param.getTotalWorkNum());
        //    private String selWorkTask;
        entity.setSelWorkTask(param.getSelWorkTask());
        //    private Integer eqRunMoldQty;
        entity.setEqRunMoldQty(param.getEqRunMoldQty());
        //    private Double piecePrice;
        entity.setPiecePrice(param.getPiecePrice());
        //    private String cusCode;
        entity.setCusCode(param.getCusCode());
        //    private Integer modQty;
        entity.setModQty(param.getModQty());
        //    private Integer proNum;
        entity.setProNum(param.getProNum());
        //    private Integer planNum;
        entity.setPlanNum(param.getPlanNum());
        //    private Integer qtyPerCarton;
        entity.setQtyPerCarton(param.getQtyPerCarton());
        //    private String workPlanCode;
        entity.setWorkPlanCode(param.getWorkPlanCode());
        //    private String workproTmBatch;
        entity.setWorkproTmBatch(param.getWorkproTmBatch());
        //    private Integer planQualfyQty;
        entity.setPlanQualfyQty(param.getPlanQualfyQty());
        //    private String tables;
        entity.setTables(param.getTables());
        //    private String isLashFlag;
        entity.setIsLashFlag(param.getIsLashFlag());
        //    private String selAfterWorkCode;
        entity.setSelAfterWorkCode(param.getSelAfterWorkCode());
        //    private Integer afteScrapQty;
        entity.setAfteScrapQty(param.getAfteScrapQty());
        //    private String poachCaseNum;
        entity.setPoachCaseNum(param.getPoachCaseNum());
        //    private String poachBox;
        entity.setPoachBox(param.getPoachBox());
        //    private String poachWorkNum;
        entity.setPoachWorkNum(param.getPoachWorkNum());
        //    private LocalDateTime poachStartDate;
        locaDateTimeString=param.getPoachStartDate();
        if(locaDateTimeString==null||locaDateTimeString.isEmpty()){

        }
        else{
            lLocalDateTime= LocalDateTime.parse(locaDateTimeString, formatter);
            entity.setPoachStartDate(lLocalDateTime);
        }
        //    private Integer poachTime;
        entity.setPoachTime(param.getPoachTime());
        //    private LocalDateTime poachEndDate;
        locaDateTimeString=param.getPoachEndDate();
        if(locaDateTimeString==null||locaDateTimeString.isEmpty()){

        }
        else{
            lLocalDateTime= LocalDateTime.parse(locaDateTimeString, formatter);
            entity.setPoachEndDate(lLocalDateTime);
        }
        return entity;
    }

    public static QingWaterboiltaskfinishEntity CopyFromWaterBoildEndParam(QingWaterboiltaskfinishParam param)
    {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        String locaDateTimeString="";
        LocalDateTime lLocalDateTime=null    ;

        QingWaterboiltaskfinishEntity entity=new QingWaterboiltaskfinishEntity();
        //workTaskCode	varchar
        entity.setWorkTaskCode(param.getZsSendWorkCode());
        //leaveQty	int
        entity.setLeaveQty(param.getLeaveQty());
        //workCode	varchar
        entity.setWorkCode(param.getProcessPlanCode());
        //proBatchNo	varchar
        entity.setProBatchNo(param.getProBatchNo());
        //proBatchTime	varchar
        entity.setProBatchTime(param.getProBatchTime());
        //finishQty	int
        entity.setFinishQty(param.getFinishQty());
        //timeOutTimeInStr	varchar
        entity.setTimeOutTimeInStr(param.getTimeOutTimeInStr());
        //leaveTime	int
        entity.setLeaveTime(param.getLeaveTime());
        //stdBoilTime	int
        entity.setNeedBoilTime(param.getNeedBoilTime());
        //boilTimeInStr	varchar
        entity.setBoilTimeInStr(param.getBoilTimeInStr());
        //cartonCode	varchar
        entity.setCartonCode(param.getCartonCode());
        //realEndBoilTime	datetime
        locaDateTimeString=param.getRealEndBoilTime();

        if(locaDateTimeString==null||locaDateTimeString.isEmpty()){

        }
        else{
            lLocalDateTime= LocalDateTime.parse(locaDateTimeString, formatter);
            entity.setRealEndBoilTime(lLocalDateTime);
        }
        //cartonName	varchar
        entity.setCartonName(param.getCartonName());
        //planQty	int
        entity.setPlanQty(param.getProdNum());
        //planEndBoilTime	datetime
        locaDateTimeString=param.getPlanEndTime();
        if(locaDateTimeString==null||locaDateTimeString.isEmpty()){

        }
        else{
            lLocalDateTime= LocalDateTime.parse(locaDateTimeString, formatter);
            entity.setPlanEndTime(lLocalDateTime);
        }
        //beginBoilTime	datetime
        locaDateTimeString=param.getStartBoilTime();
        if(locaDateTimeString==null||locaDateTimeString.isEmpty()){

        }
        else{
            lLocalDateTime= LocalDateTime.parse(locaDateTimeString, formatter);
            entity.setStartBoilTime(lLocalDateTime);
        }
        //qualifyQty	int
        entity.setQualifyQty(param.getQualifyQty());
        //invName	varchar
        entity.setInvName(param.getInvName());
        //invCode	varchar
        entity.setInvCode(param.getInvCode());
        //timeOutTimeInSecond	int
        entity.setTimeOutTimeInSecond(param.getTimeOutTimeInSecond());
        //boilTimeInSecond	int
        entity.setBoilTimeInSecond(param.getBoilTimeInSecond());
        //psnCode	varchar
        entity.setPsnCode(param.getPsnCode());
        //psnName	varchar
        entity.setPsnName(param.getPsnName());


        return entity;
    }

}
